#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 105;
const int MOD = 1e9 + 7;
const int MX = 100;

ll n, m;
int cnt1[N], cnt2[N], cnt[N];
ll a[N][N];
void matmul(ll a[N][N], ll b[N][N], ll c[N][N]) {
  ll res[N][N] = {0};
  rep(i, 0, MX - 1) rep(j, 0, MX - 1) rep(k, 0, MX - 1) {
    res[i][j] = (res[i][j] + a[i][k] * b[k][j] % MOD) % MOD;
  }
  rep(i, 0, MX - 1) rep(j, 0, MX - 1) c[i][j] = res[i][j];
}
void matpow(ll b[N][N], ll p, ll c[N][N]) {
  ll res[N][N] = {0};
  rep(i, 0, MX - 1) res[i][i] = 1;
  while (p) {
    if (p & 1) matmul(res, b, res);
    matmul(b, b, b);
    p >>= 1;
  }
  rep(i, 0, MX - 1) rep(j, 0, MX - 1) c[i][j] = res[i][j];
}
void out(ll a[N][N]) {
  rep(i, 0, MX - 1) {
    rep(j, 0, MX - 1) cout << a[i][j] << ' ';
    cout << endl;
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  cin >> m;
  rep(i, 1, m) {
    int x;
    cin >> x;
    cnt1[x] = 1;
  }
  cin >> m;
  rep(i, 1, m) {
    int x;
    cin >> x;
    cnt2[x] = 1;
  }
  rep(i, 1, MX) cnt[i] = cnt1[i] & cnt2[i];
  rep(i, 0, MX - 2) a[i][i + 1] = 1;
  rep(i, 0, MX - 1) a[MX - 1][i] = cnt[MX - i];
  matpow(a, n, a);
  cout << a[MX - 1][MX - 1];
  return 0;
}